#include <bits/stdc++.h>
using namespace std;

int main(){
    unordered_map<string, int> date(
    {{"monday" , 1}, {"tuesday", 2}, {"wednesday", 3}, 
     {"thursday", 4}, {"friday", 5}, {"saturday", 6}, {"sunday", 7}
    });
    int n;
    cin >> n;
    while(n--){
        string startdate, enddate;
        int least, most;
        cin >> startdate >> enddate >> least >> most;
        int daypast = date[enddate] - date[startdate] + 1;
        while(daypast < least) daypast += 7;
        vector<int> ans;
        while(daypast <= most){
            ans.push_back(daypast);
            daypast += 7;
        }
        if(ans.size() == 0) cout << "impossible" << endl;
        else if(ans.size() == 1) cout << ans[0] << endl;
        else cout << "many" << endl;
    }
}